package edu.hqu.deepspace.controller;

import edu.hqu.deepspace.pojo.Order;
import edu.hqu.deepspace.pojo.Product;
import edu.hqu.deepspace.pojo.User;
import edu.hqu.deepspace.service.OrderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/Admin")
public class OrderController {
    @Autowired
    @Qualifier("OrderServiceImpl")
    private OrderService orderService;

    @RequestMapping("/order")
    public String list(Model model){
        List<Order> list =orderService.queryOrder();
        model.addAttribute("list", list);
        return "Order";
    }




    @RequestMapping("/toAddOrder")
    public String toAddPaper() {
        return "addOrder";
    }
    @RequestMapping("/addOrder")
    public String addPaper(Order order) {
        System.out.println(order);
        orderService.addOrder(order);
        return "redirect:/Admin/order";
    }

    @RequestMapping("/toUpdateOrder")
    public String toUpdateOrder(Model model, int oid) {
        Order order = orderService.queryOrderById(oid);
        System.out.println(order);
        model.addAttribute("Qorder",order);
        return "updateOrder";
    }

    @PostMapping("/updateOrder")
    public String updateBook(Model model, Order order) {
        System.out.println(order);
        orderService.updateOrder(order);
        Order order1 = orderService.queryOrderById(order.getOid());
        model.addAttribute("order", order1);
        return "redirect:/Admin/order";
    }

    @RequestMapping("/del2/{oid}")
    public String deleteUser(@PathVariable("oid") int oid) {
        orderService.deleteOrder(oid);
        return "redirect:/Admin/order";
    }

    @RequestMapping("/query")
    public String queryProduct(Model model, String oid){
            int oid1=Integer.parseInt(oid);
            Order order = orderService.queryOrderById(oid1);
            model.addAttribute("order", order);
            return "queryOrder";}


}
